

/*
plot example yield curve response

output:
- f4c_*.pdf: plots of yield curve response around example auctions

*/


* plotting options
set scheme lean_uncluttered


********************************************************************************
********************************************************************************

use ../data/auction_notesbonds_govpx_shock_all.dta, clear

* only use regularly traded securities
drop if when_issued
drop when_issued
* drop any maturity with less than 1 year until maturity
drop if maturity_remaining<30
* convert maturity remaining/lapsed into years
replace maturity_remaining = maturity_remaining/365
replace maturity_lapsed = maturity_lapsed/365

* drop old bonds
*drop if maturity_lapsed>15 & maturity_remaining<10

* drop if too few observations in govpx shocks
gen N_obs = N_obs_pre + N_obs_post
drop if N_obs<10

* examples
* December 9, 2010 (auction: 912810QL5; re-opened 30Y)
* August 11, 2011 (auction: 912810QS0; newly issued 30Y)
* August 12, 2009 (auction: 912828LJ7; newly issued 10Y)
* January 11, 2017 (auction: 912828U24; re-opened 10Y)
local datenums `=mdy(12,9,2010)' `=mdy(8,11,2011)' ///
	`=mdy(8,12,2009)' `=mdy(1,11,2017)'
local cusips 912810QL5 912810QS0 912828LJ7 912828U24

* titles
local title_strs `" "Panel A: 30-year Auction (Dec 9, 2010)" "'
local title_strs `" `title_strs' "Panel B: 30-year (Aug 11, 2011)" "'
local title_strs `" `title_strs' "Panel C: 10-year (Aug 12, 2009)" "'
local title_strs `" `title_strs' "Panel D: 10-year (Jan 11, 2017)" "'


forvalues i=1/4 {
	local datenum: word `i' of `datenums'
	local cusip: word `i' of `cusips'
	local title_str: word `i' of `title_strs'
	* x-titles: bottom only
	if inlist(`i', 3, 4) local x_axis_str xtitle("Maturity")
	else local x_axis_str xtitle("")
	* y-titles: left only
	if inlist(`i', 1, 3) local y_axis_str ytitle("{&Delta} Yield (b.p.)")
	else local y_axis_str ytitle("")
	
	
	cap drop mm b_yld se_yld yld_ci_l yld_ci_u
	* local mean-smoothing (save results only)
	lpoly D_shock maturity_remaining ///
		if auctionDate==`datenum' & cusip=="`cusip'", ///
		bw(1) ci nograph gen(mm b_yld) se(se_yld) n(100)
	gen yld_ci_l = b_yld - 2*se_yld
	gen yld_ci_u = b_yld + 2*se_yld
	
	* plot
	twoway (rarea yld_ci_l yld_ci_u mm , color(gs12) ) ///
		(line b_yld mm, lcolor("scheme p1") lwidth(medium) lpattern(solid)) ///
		, title("`title_str'") `y_axis_str' `x_axis_str' ///
		legend(off) name("shock_yld`i'", replace) nodraw
}
* combine with correct size and export
local fname f4c_yld_curve_response_examples
graph combine shock_yld1 shock_yld2 shock_yld3 shock_yld4, ///
	rows(2) imargin(tiny) xsize(8) ysize(5) name(`fname', replace)
graph export ../figs/`fname'.pdf, replace
graph export ../figs/`fname'.eps, replace



